<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<link href="<%=path%>/static/css/bootstrap.min.css" rel="stylesheet">
<script src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<script src="<%=path%>/static/js/bootstrap.min.js"></script>
</head>
<body>

	<!-- 弹出结果 -->
	<c:if test="${not empty myInfo}">
		<script type="text/javascript" language="javascript">
        {
            alert("<%=request.getAttribute("myInfo")%>
			");
			}
		</script>
	</c:if>

	<!-- 引入header文件 -->
	<%@ include file="header.jsp"%>

	<div class="panel panel-default" id="login"
		style="width: 20%; margin-left: 40%; margin-top: 5%; margin-bottom: 5%">
		<div class="panel-heading" style="background-color: #fff">
			<h3 class="panel-title">欢迎登录</h3>
		</div>
		<form class="form-signin" action="userLogin.do" method="post"
			id="myLoginForm">
			<label>用户名</label> <input type="text" class="form-control"
				name="userName" placeholder="请输入用户名" id="userName" /> <label>密码</label> <input
				type="password" class="form-control" name="userPassword"
				placeholder="请输入密码" id="userPassword" /> <input type="hidden" name="tipId"
				value="<%=request.getParameter("tipId")%>" />
			<div class="checkbox text-left" />
			<label> <input type="checkbox" id="remember" name="remember">记住密码</input>
			</label> <a style="margin-left: 30%" href="#">忘记密码?</a> <br/>${error }
			<p style="text-align: right; color: red; position: absolute"
				id="info"></p>
			<br /> <input type="submit" class="btn btn-success btn-block"
				value="登录" onclick="login_check()" /> <a href="toSignUpPage.do"
				class="btn btn-default btn-block">注册</a>
		</form>
	</div>

	<script type="text/javascript" language="javascript">
		function login_check() {
			var form = document.getElementById("myLoginForm"); // 由id获取表单
			var uname = form.userName.value; // 获取输入的用户名
			var upwd = form.userPassword.value; // 获取输入的密码
			if (uname == '' || upwd == '') {
				alert("请将登录信息填写完整！");
			} else {
				form.submit(); // 提交表单
			}
		}

		$(document).ready(function() {
			//记住密码功能
			var str = getCookie("loginInfo");
			str = str.substring(1, str.length - 1);
			var userName = str.split(",")[0];
			var userPassword = str.split(",")[1];
			//自动填充用户名和密码
			$("#userName").val(userName);
			$("#userPassword").val(userPassword);
		});

		//获取cookie
		function getCookie(cname) {
			var name = cname + "=";
			var ca = document.cookie.split(';');
			for (var i = 0; i < ca.length; i++) {
				var c = ca[i];
				while (c.charAt(0) == ' ')
					c = c.substring(1);
				if (c.indexOf(name) != -1)
					return c.substring(name.length, c.length);
			}
			return "";
		}

		//记住密码功能
		function remember() {
			var remFlag = $("input[type='checkbox']").is(':checked');
			if (remFlag == true) { //如果选中设置remFlag为1
				//cookie存用户名和密码,回显的是真实的用户名和密码,存在安全问题.
				var conFlag = confirm("记录密码功能不宜在公共场所(如网吧等)使用,以防密码泄露.您确定要使用此功能吗?");
				if (conFlag) { //确认标志
					$("#remember").val("1");
				} else {
					$("input[type='checkbox']").removeAttr('checked');
					$("#remember").val("");
				}
			} else { //如果没选中设置remFlag为""
				$("#remember").val("");
			}
		}
	</script>

</body>
</html>